import Vue from 'vue'
import App from './App'
import store from './static/js/store/store.js';
import config from './static/js/config.js';
Vue.prototype.$config = config;
import * as http from './static/js/request.js';
Vue.prototype.$http  = http;

import md5 from './static/js/md5.js';
Vue.prototype.$Md5  =  md5;

//权限相关的判断
import {common} from './static/js/mixin/common.js';
Vue.mixin(common);

// 挂载全局方法
import configs from "./common/config.js"
Vue.prototype.configs=configs

// import lib from "./common/lib.js"
// Vue.prototype.lib=lib

import request from "./common/request.js";
Vue.prototype.$httpas = request;


import ZAudio from '@/components/uniapp-zaudio/index.js'
// import ZAudio from 'uniapp-zaudio' // npm引用方式

const url = 'https://xcx.htxxkj.net/api/user.v1_0.'; 
 // const url ='https://test.baohuiinfo.com/api/applets.v1_0.'
const agentId = '188'
const ajax = function(methods, ajaxurl, object_) {
	let ajaxobj = object_ ? object_ : {};
	let token = uni.getStorageSync('token');
	let busId = uni.getStorageSync('busId');
	// #ifdef H5
	if (token) ajaxobj.token = token;
	// #endif
	return new Promise((resolve, reject) => {
		if(ajaxobj.loding===false){delete ajaxobj.loding}else{uni.showLoading({title:'加载中~'})};
		uni.request({
			data: ajaxobj,
			method: methods.toUpperCase(),
			header:{
				"agentId":agentId,
				token:token?token:'',
				busId:busId?busId:''
			},
			url: url + ajaxurl,
			dataType: "json",
			success(res) {
				uni.hideLoading()
				if (res.data.code * 1 == 244 ) {
					uni.clearStorage();
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					})
				} else if (res.data.code * 1 == 1) {
					resolve(res.data)
				} else {
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
					//reject("接口错误");
				}
			},
			fail(res) {
				uni.getNetworkType({
					success: function(res) {
						if (res.networkType == 'none') {
							uni.showToast({
								title: '网络开小差了···',
								icon: "none"
							})
						}
					}
				});
			}
		})
	})
}

Vue.prototype.$ajax = ajax;
console.log(`ZAudio当前版本`,ZAudio.version)
let zaudio = new ZAudio({
	continuePlay: true, //续播
	autoPlay: false, //自动播放 部分浏览器不支持
})
Vue.prototype.$zaudio = zaudio
Vue.prototype.$mbgColor='#ffffff'
//this.$mbgColor
//模拟初始数据
var data = [];
// 设置音频数据
//zaudio.setAudio(data)
//渲染第一首音频
//zaudio.setRender(0)

Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()